<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog" width="900px" @open="open" @close="close" top="10px" :append-to-body="true" :modal-append-to-body="true">
    <div style="padding-bottom:10px">
      <!-- 查询界面 -->
      <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false">
        <template slot="search">
          <el-form-item label="名称">
            <el-input v-model="queryParam.qry_name" placeholder=""></el-input>
          </el-form-item>
        </template>
      </tl-list-search>
      <!-- 列表界面 -->
      <div>
        <!-- 列表选择 -->
        <div class="table-alert-div" ref="selector">
          <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
            <template slot="title">
              已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRows.length }}</a
              >项&nbsp;&nbsp;
              <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
            </template>
          </el-alert>
        </div>
        <!--表格渲染-->
        <el-table class="tl-table" ref="mainTable" :height="tableHeight" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
          <el-table-column type="selection" width="55px" fixed="left" v-if="isSingleSelect === false" :reserve-selection="true"> </el-table-column>
          <el-table-column prop="milepostname" label="里程碑及任务名称" width="150px" sortable="custom" sort-by="milepostname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="milepostcode" label="编码" width="150px" sortable="custom" sort-by="milepostcode" align="center" header-align="center"></el-table-column> -->
          <el-table-column prop="deliverable" label="交付成果" sortable="custom" sort-by="deliverable" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="responsible" label="责任人" width="100px" sortable="custom" sort-by="responsible" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="planfinishtime" label="计划达成时间" width="170px" sortable="custom" sort-by="planfinishtime" align="center" header-align="center" :formatter="dateFormat"></el-table-column>
          <!-- <el-table-column prop="dispactualfinishtime" label="实际达成时间" width="100px" sortable="custom" sort-by="actualfinishtime" align="center" header-align="center"></el-table-column> -->
          <!-- <el-table-column prop="dispmilepoststate" label="里程碑及任务状态" width="100px" sortable="custom" sort-by="milepoststate" align="center" header-align="center"></el-table-column> -->
          <!-- <el-table-column prop="sourcetype" label="来源类型" width="150px" sortable="custom" sort-by="sourcetype" align="center" header-align="center"></el-table-column>
          <el-table-column prop="sourceid" label="来源id" width="150px" sortable="custom" sort-by="sourceid" align="center" header-align="center"></el-table-column>
          <el-table-column prop="planid" label="策划书id" width="150px" sortable="custom" sort-by="planid" align="center" header-align="center"></el-table-column>
          <el-table-column prop="state" label="审批状态" width="150px" sortable="custom" sort-by="state" align="center" header-align="center"></el-table-column>
          <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center"></el-table-column> -->
          <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
              <el-tag v-else type="danger">否</el-tag>
            </template>
          </el-table-column> -->
          <el-table-column label="操作" width="80px" align="center" fixed="right" v-if="isSingleSelect === true">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-finished" @click="doSelectData(scope.row[fieldDefaultKey])">选择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 列表分页 -->
        <el-row class="pagebar" ref="pager">
          <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
        </el-row>
      </div>
    </div>
    <div slot="footer" class="dialog-footer" v-if="isSingleSelect === false">
      <el-button type="text" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doConfirm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
// 该组件引用平台mixin组件会导致无法打包，重写平台组件
import { mixin_ref_list } from '../../../mixins/mixin_ref_list'
/** 子组件 */
import { validateNull } from '@tapui/utils/validate'
/** 工具类 */
import { queryDataCode } from '@tapui/api/dataCode'
import { getAction, putAction, postAction } from '@tapui/utils/http'
import { filterObjectNull } from '@tapui/utils/util'
/** VUE配置 */
export default {
  name: 'TlMpmProjectMilepostRef',
  components: {},
  mixins: [mixin_ref_list],
  data() {
    return {
      description: '项目策划-里程碑及任务参照页面',
      // 默认Key字段名
      fieldDefaultKey: 'id',
      // 默认显示字段名
      fieldDefaultValue: 'name',
      // url配置
      url: {
        list: '/mpm/projectMilepost/refList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode',
        sord: 'asc'
      }
    }
  },
  props: {
    viewAllMilePost: {
      type: Boolean,
      default: false
    },
    superviseObjectCode2: {
      type: String,
      default: ''
    },
    queryType: {
      type: String,
      default: ''
    }
  },
  methods: {
    /** 查询数据 */
    loadData(paramMap) {
      if (!this.url.list) {
        this.$tap.alert('请设置查询数据地址!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      // 查询条件
      var params = this.getQueryParams()
      params.queryType = this.queryType
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            this.datas = res.result.dataList
            if (this.superviseObjectCode2 !== '') {
              var superviseObjectCode = this.superviseObjectCode2.split(',')
              setTimeout((_) => {
                for (let j = 0; j < superviseObjectCode.length; j++) {
                  for (let i = 0; i < this.datas.length; i++) {
                    if (superviseObjectCode[j] === this.datas[i].milepostcode) {
                      this.$refs.mainTable.toggleRowSelection(this.datas[i], true)
                    }
                  }
                }
              }, 50)
            }
            this.pageInfo.totalCount = res.result.totalCount
          } else {
            this.$tap.alert(res.message)
          }
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      Object.assign(param, this.queryParam, this.externalQueryParam, this.filtersInfo, this.sorterInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      param.qry_enabled = 1
      param.currentUser = this.$store.getters.user.code
      param.viewAllMilePost = this.viewAllMilePost
      return filterObjectNull(param)
    }
  }
}
</script>

<style lang="scss" scoped>
/** “暂无数据”居中显示 */
.tl-table {
  /deep/ .el-table__empty-text {
    text-align: center;
  }
}
/** 表格上边、左边的线 */
.el-table--border,
.el-table--group {
  border: none;
}
/**  表格下边的线 */
.el-table--border::before,
.el-table--group::before {
  width: 0;
}
/**  表格右边的线 */
.el-table--border::after,
.el-table--group::after {
  height: 0;
}
</style>
